

********************************************************
** Table 3
********************************************************


global data="C:\CFLs\Data\"
global outputs="C:\CFLs\Outputs\"

clear all
clear matrix
clear mata

set maxvar 10000
set matsize 11000

cd "$data"

use "hh_panel_trtmt.dta"  // REQUIRES ELECTRICITY UTILITY DATA 


* Drop outliers: top 1% of observations each month (w.r.t. electricity bill) 
replace elec=. if elec_xt10_==1  

* Drop movers: households that moved  between intervention and follow-up survey (101 households)
drop if movers_v1== 1  /*leaves: 899 HHs */


* Limit to period of 2 years prior to intervention
drop if time<201104

* Limit to period before tariff change 
keep if time<201410


* globals for analysis, tables, etc.
xtset hh_id time

global elecheat="s7_1_5_1_b" // whether the house reports heating with electricity at baseline 
global bill="collect_days"  // # of days within a billing period
global format=`"nogap label nostar starlevels(* 0.1 ** 0.05 *** 0.01) collabels(none) cells(b(star fmt(3) label(Coef.)) se(par fmt(3) label(Std.Err.))) csv"'
global statsFEshort=`"stats(N r2, fmt(0 a2) labels("Observations" "R-squared")) "'
save temp_elec.dta , replace 

* Calculate omitted group means 
tabstat elec if TGH_T==0 & TGH_S==0 & TGL_T==0 & TGL_S==0 & post==0
tabstat elec if TGH_T==0 & TGH_S==0 & TGL_T==0 & TGL_S==0 

use  temp_elec.dta , clear
global regoutfile = "Table_elec_RESTAT.csv"
capture: erase $regoutfile

* Col 1
eststo:  xtreg elec TGH_Tpost TGH_Spost TGL_Tpost TGL_Spost TGH_T TGH_S TGL_T TGL_S post  s7_1_5_1_b  hdd  $bill     i.hh_id      i.time , vce(cl hh_id)
 test TGH_Tpost = TGL_Tpost
 test TGH_Spost = TGL_Spost
 
* Col 2
eststo:  xtreg elec TGH_Tpost TGH_Spost TGL_Tpost TGL_Spost TGH_T TGH_S TGL_T TGL_S  post s7_1_5_1_b   hdd  $bill     i.hh_id#i.season    i.time , vce(cl hh_id)
 test TGH_Tpost = TGL_Tpost
 test TGH_Spost = TGL_Spost

* Col 3
eststo:  xtreg elec TGH_Tpost TGH_Spost TGL_Tpost TGL_Spost TGH_T TGH_S TGL_T TGL_S post  s7_1_5_1_b  hdd  $bill     i.hh_id  i.within_village_cluster#i.season      i.time , vce(cl hh_id)
 test TGH_Tpost = TGL_Tpost
 test TGH_Spost = TGL_Spost

esttab using $regoutfile, keep(_cons TGH_Tpost* TGH_Spost* TGL_Tpost* TGL_Spost*  post  TGH_T TGH_S TGL_T TGL_S     hdd  $bill   ) $format $statsFEshort title("TABLE X  :   Outcome= Electricity use ") append 





